<template>
  <div class="app">
    <div class="top-img">
      <img src="http://10.31.165.35:3000/images/index/3.png" alt="" />
    </div>
    <div class="location-fa">
      <div class="location">
        <van-tabs
          v-model:active="active"
          type="card"
          color="#F9FBFD"
          title-active-color="black"
          title-inactive-color="black"
        >
          <van-tab title="国内">
            <div class="location-con">
              <ul>
                <li>
                  <label>地区</label>
                </li>
                <li><label>日期</label></li>
                <li><label>详细位置</label></li>
                <li><label>详细位置</label></li>
              </ul>
            </div>
          </van-tab>
          <van-tab title="海外">
            <div class="location-con">
              <ul>
                <li><label>国家</label></li>
                <li><label>日期</label></li>
                <li><label>详细位置</label></li>
                <li><label>详细位置</label></li>
              </ul>
            </div>
          </van-tab>
        </van-tabs>
        <button>查询</button>
      </div>
    </div>
    <div class="query">
      <h2>最近查询</h2>
      <div v-show="scroll > 550" class="search">
        <van-search
          v-model="value"
          placeholder="请输入搜索关键词"
          label="杭州"
          shape="round"
          background="transparent"
        />
      </div>
      <div class="query-con">
        <ul>
          <li v-for="item in liveimg" :key="item.imgurl">
            <img :src="item.imgurl" alt="" />
            <span>{{ item.title }}</span>
            <p>{{ item.description }}</p>
          </li>
        </ul>
      </div>
    </div>
    <footer>
      <van-tabbar v-model="active" :placeholder="true">
        <van-tabbar-item icon="like-o">收藏</van-tabbar-item>
        <van-tabbar-item icon="todo-list-o">我的订单</van-tabbar-item>
      </van-tabbar>
    </footer>
  </div>
  <div class="fanhui" @click="fanhui">
    <van-icon name="arrow-left" />
  </div>
</template>

<script>
import { ref, onMounted, computed } from "vue";
import { useStore } from "vuex";
import { areaList } from "@vant/area-data";
import { useRouter } from "vue-router";
export default {
  setup() {
    const store = useStore();
    const active = ref(0);
    const scroll = ref("");
    const router = useRouter();
    const fanhui = () => {
      router.go(-1);
    };
    onMounted(() => {
      store.dispatch("getLiveImg");
    });
    const liveimg = computed(() => {
      console.log(store.state.liveimg);
      return store.state.liveimg;
    });
    return { active, scroll, liveimg, areaList, fanhui };
  },
  methods: {
    handleScroll() {
      this.scroll =
        document.documentElement.scrollTop || document.body.scrollTop;
    },
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  // 及时销毁，否则影响其他路由
  unmounted() {
    window.removeEventListener("scroll", this.handleScroll);
  },
};
</script>
<style lang="less" scoped>
.fanhui {
  position: absolute;
  top: 12px;
  left: 0;
  font-size: 18px;
  color: white;
  display: block;
  width: 20px;
  height: 20px;
  z-index: 5;
}
.top-img {
  img {
    width: 100%;
    height: 161px;
  }
}
.location-fa {
  height: 349px;
  position: relative;
  margin-bottom: 20px;
  .location {
    width: 357px;
    margin: 0 auto;
    padding-bottom: 20px;
    background-color: #ffffff;
    position: absolute;
    left: 10px;
    top: -60px;
    button {
      display: block;
      width: 318px;
      height: 36px;
      background-image: linear-gradient(to right, #fb8527, #fc642f);
      margin-left: 20px;
      margin-top: 20px;
      border-radius: 6px;
      border: none;
    }
    .location-con {
      ul {
        padding: 0 20px 0 20px;
        li {
          width: 100%;
          height: 76px;
          font-size: 14px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #070707;
          // line-height: 76px;
          border-bottom: 1px solid #000;
          position: relative;
          :root {
            --van-button-large-height: 30px;
          }
          label {
            position: absolute;
            bottom: 10px;
          }
        }
      }
    }
  }
}

.query {
  background-color: #fff;
  padding-top: 15px;
  position: relative;
  .search {
    position: fixed;
    top: 0;
    left: 35px;
    z-index: 10;
    width: 318px;
  }
  h2 {
    font-size: 15px;
    font-weight: 400;
    color: #646464;
    line-height: 12px;
    text-align: center;
    margin-bottom: 15px;
  }
  .query-con {
    ul {
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
      li {
        img {
          width: 170px;
          height: 125px;
          border-radius: 5px;
        }
        span {
          width: 160px;
          text-align: center;
          display: block;
          font-size: 11px;
          font-family: PingFang SC;
          font-weight: 800;
          color: #cd7d44;
          line-height: 12px;
          margin-bottom: 8px;
        }
        p {
          text-align: center;
          padding-left: 30px;
          width: 160px;
          height: 24px;
          font-size: 14px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #323232;
          line-height: 12px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }
      }
    }
  }
}
</style>
